package com.highper.gateway.configure;

import cn.dev33.satoken.reactor.filter.SaReactorFilter;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import com.highper.common.constant.ExceptionMessageConstant;
import com.highper.common.constant.NumberConstant;
import com.highper.common.constant.ResponseCodeConstant;
import com.highper.common.constant.UrlConstant;
import com.highper.common.entity.response.HighperResponse;
import com.highper.common.mapper.GatewayListMapper;
import com.highper.common.util.WebFluxUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;

/**
 * @Author ZhangGJ
 * @Date 2022/01/24 16:08
 */
@Slf4j
@Configuration
public class SaTokenConfigure {

    private final GatewayListMapper gatewayListMapper;

    @Autowired
    public SaTokenConfigure(GatewayListMapper gatewayListMapper) {
        this.gatewayListMapper = gatewayListMapper;
    }

    @Bean
    public SaReactorFilter getSaReactorFilter() {
        String[] whites = gatewayListMapper.selectGatewayList(NumberConstant.ONE);
        return new SaReactorFilter()
                .addInclude(UrlConstant.ALL)
                .addExclude(UrlConstant.FAVICON)
                .setAuth(obj -> SaRouter.notMatch(whites).match(UrlConstant.ALL, StpUtil::checkLogin));
    }
}
